<template>
	<view>
		<view class="main">
			<!-- <view class="shuru">
				<text class="shuru_tit t1">红包状态</text>
				<switch class="shuru_text t1" :checked="checks" @change="checki"></switch>
			</view> -->
			<view class="shuru">
				<text class="shuru_tit t1">红包返利利率(%)</text>
				<input type="number" value="" placeholder="请输入红包返利利率" class="shuru_text t1" v-model="lilv" />
			</view>
			<!-- <view class="shuru"> -->
				<text class="shuru_tit t7">注:最大不超过25%</text>
			<!-- </view> -->
			<view class="shuru">
				<text class="shuru_tit t1">红包返利天数</text>
				<input type="number" value="" placeholder="请输入红包返利天数" class="shuru_text t1" v-model="tian" />
			</view>
				<text class="shuru_tit t7">注:不超过100天</text>
		</view>
		<view class="tuic t2" @click="shezhi()">确定</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lilv: '',
				tian: '',
				lilv1: '',
				tian1: '',
				checks: false,
				mainid: ''
			}
		},
		onLoad() {
			var _this = this;
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
					_this.set();
				}
			});
		},
		methods: {
			checki(e) {
				console.log(e);
				this.checks = e.detail.value;
			},
			tishis(e) {
				this.tishi = true;
				// console.log(e);
				this.delid = e;

			},
			clos() {
				this.tishi = false;

			},
			set() {
				var _this = this;
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/getRedConfig/' + _this.mainid, //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						"id": _this.mainid,
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log(res);
						if (res.data.status == '200') {
							_this.tian = res.data.data.days;
							_this.lilv = res.data.data.proportion/100;
							_this.tian1 = res.data.data.days;
							_this.lilv1 = res.data.data.proportion/100;
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						// this.checks = true
						console.log(error)
					}
				});
			},
			shezhi() {
				var _this = this;
				var str =/^\+?[1-9][0-9]*$/;
				if (_this.lilv == _this.lilv1 && _this.tian == _this.tian1) {
					uni.showToast({
						title: '数据暂无修改',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!_this.lilv) {
					uni.showToast({
						title: '请输入红包返利利率',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				 // else if (!(str.test(_this.lilv))) {
					// 	uni.showToast({
					// 		title: '红包返利利率必须为正整数',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return false
					// }
				if (!_this.tian) {
					uni.showToast({
						title: '请输入红包返利天数',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				 // else if (!(str.test(_this.tian))) {
					// 	uni.showToast({
					// 		title: '红包返利天数必须为正整数',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return false
					// }
					console.log(_this.tian);
					console.log(_this.mainid);
					console.log(_this.lilv);
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/setRedConfig', //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						"days": _this.tian, //发放天数
						"id": _this.mainid,
						"proportion": _this.lilv*100 //发放比例
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log(res);
						if (res.data.status == '200') {
							uni.showToast({
								title: '红包设置成功',
								icon: 'none',
								duration: 2000
							});
							setTimeout(function() {

								uni.navigateBack({
									delta: 1
								})
							}, 2000)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						// this.checks = true
						console.log(error)
					}
				});
			},
		}
	}
</script>

<style>
	.baodan_xuzhi_main {
		width: 100%;
		height: 100vh;
		display: block;
		float: left;
		background: url(../../static/img/bg.png) repeat;
		position: fixed;
		top: 0;
		left: 0;
	}

	.baodan_xuzhi_tit {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		display: block;
		float: left;
		text-align: center;
	}

	.baodan_xuzhi_info {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
		margin-top: 2vw;
	}

	.baodan_clo {
		width: 6vw;
		height: 6vw;
		display: block;
		float: left;
		position: absolute;
		top: 2vw;
		right: 2vw;
		border-radius: 50%;
		border: 1px solid #000;
		padding: 1vw;
	}

	.baodan_clo image {
		width: 3.7vw;
		height: 3.7vw;
		display: block;
		float: left;
	}

	.kaitong {
		width: 80%;
		height: 12vw;
		display: block;
		float: left;
		background: url(../../static/img/but1.png) no-repeat top center;
		background-size: 100%;
		margin: 2vw 10%;
		text-align: center;
		line-height: 12vw;
	}

	.center_top {
		width: 100%;
		height: auto;
		display: block;
		float: left;
	}

	.baodan_list {
		width: 90%;
		height: auto;
		display: block;
		float: left;
		margin: 2vw 5%;
		background: #fff;
		border-radius: 2vw;
		padding: 4vw;
		box-shadow: 0px 0px 1vw #ccc;
		margin-top: 4vw;
	}

	.baodan_list_tit {
		width: 75%;
		height: auto;
		display: block;
		float: left;
	}

	.baodan_but {
		width: 20%;
		height: 6vw;
		display: block;
		float: right;
		border-radius: 2vw;
		background: url(../../static/img/but.png) no-repeat top center;
		background-size: 100%;
		line-height: 6vw;
		text-align: center;
		margin-top: 3vw;
	}

	.baodan_xuzhi {
		width: 80%;
		height: auto;
		display: block;
		float: left;
		background: #fff;
		box-shadow: 0px 0px 2vw #999;
		padding: 4vw;
		position: fixed;
		top: 40vw;
		left: 10%;
		border-radius: 2vw;
	}

	.baodan_xuzhi_tit {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		display: block;
		float: left;
		text-align: center;
	}

	.baodan_into {
		position: relative;
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
		margin-top: 2vw;
		overflow: hidden;
	}

	.baodan_into::after {
		width: 7vw;
		height: 7vw;
		content: "…";
		position: absolute;
		top: 0;
		right: 0;
		background: #fff;
		padding-left: 2vw;
		display: block;
		float: right;
	}

	.shuru {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		border-radius: 1vw;
		overflow: hidden;
		padding: 2vw 4vw;
		background: #fff;
		margin-top: 3vw;
		box-shadow: 0px 0px 5px #eee;
	}

	.shuru_tit {
		width: 35%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text {
		width: 60%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: right;
		text-align: right;
	}
</style>
